//
//  DCAuthStatusView.m
//  Demo
//
//  Created by zhaolin on 2023/1/9.
//

#import "DCAuthStatusView.h"

@interface DCAuthStatusView ()

@property (nonatomic, strong) NSMutableArray *viewArr;

@property (nonatomic, strong) UILabel *currentNum;

@end

@implementation DCAuthStatusView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configureAlloc];
        [self configureUI];
    }
    return self;
}
- (void)configureAlloc {
    self.viewArr = @[].mutableCopy;
}

- (void)configureUI {
    self.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    UIView *bgColor = [UIView new];
    bgColor.backgroundColor = [UIColor colorWithString:@"#444342"];
    bgColor.layer.masksToBounds = YES;
    bgColor.layer.cornerRadius = 8;
    [self addSubview:bgColor];
    [bgColor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(120);
        make.top.mas_equalTo(10);
    }];
    
    UILabel *limitLabel = [UILabel new];
    limitLabel.text = @"Current limit：";
    limitLabel.textColor = [UIColor colorWithString:@"#E1FE97"];
    limitLabel.font = DCFont_PF_Regular(14);
    [bgColor addSubview:limitLabel];
    [limitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(38);
        make.top.mas_equalTo(25);
    }];
    
    UILabel *moneyLabel = [UILabel new];
    moneyLabel.text = @"₦ 3000";
    moneyLabel.textColor = [UIColor colorWithString:@"#E1FE97"];
    moneyLabel.font = DCFont_PF_Semibold(18);
    [bgColor addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(25);
        make.right.mas_equalTo(-38);
    }];
    
    CGFloat spacing = (kScreenWidth - 15*2 - 38*2 - 30 *6)/5.0;
    for (int i = 0; i < 6; i++) {
        UIView *lineView = [UIView new];
        [self.viewArr addObject:lineView];
        lineView.layer.cornerRadius = 3;
        lineView.layer.masksToBounds = YES;
        lineView.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
        [bgColor addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(limitLabel.mas_bottom).mas_offset(25);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(6);
            make.left.mas_equalTo(38 + 30*i + spacing*i);
        }];
    }
    
    UILabel *totalLabel = [UILabel new];
    totalLabel.text = @"6";
    totalLabel.textColor = [UIColor colorWithString:@"#FFFFFF"];
    totalLabel.font = DCFont_PF_Semibold(12);
    [bgColor addSubview:totalLabel];
    [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(bgColor.mas_centerX);
        make.bottom.mas_equalTo(-11);
    }];
    
    UILabel *currentNum = [UILabel new];
    _currentNum = currentNum;
    currentNum.text = @"1/";
    currentNum.textColor = [UIColor colorWithString:@"#E1FE97"];
    currentNum.font = DCFont_PF_Semibold(12);
    [bgColor addSubview:currentNum];
    [currentNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(bgColor.mas_centerX);
        make.bottom.mas_equalTo(totalLabel.mas_bottom);
    }];
    [self setColorToIndex:0];
}

- (void)setColorToIndex:(NSInteger)index {
    if (index > self.viewArr.count) {
        return;
    }
    _currentNum.text = [NSString stringWithFormat:@"%ld/",index+1];
    for (int i=0; i < 6; i++) {
        UIView *lineView = [self.viewArr objectAtIndex:i];
        if (i <= index) {
            lineView.backgroundColor = [UIColor colorWithString:@"#E1FE97"];
        } else {
            lineView.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
